'''
Created on 07/06/2010

@author: Will
'''
import random
from objects.pc import Pc
from objects.realObject import RealObject
from objects.decalObject import DecalObject
from objects.realRoundObject import RealRoundObject
import math
from utils import globals
from objects.CrossHair import CrossHair
from objects.car.car import Car

class EntitySpawner(object):
    
    def __init__(self,world):
        self.world = world
        self.player = None
    
    def spawnRandomEntity(self,nothing):
        if random.uniform(0,2) > 1:
            self.spawnEntity(nothing)
        else:
            self.spawnRoundEntity(nothing)
    def spawnEntity(self,nothing):
        
        #x = random.uniform(-100.0, 100.0)
        x = random.uniform(-500.0, 500.0)
        y = random.uniform(-500.0, 500.0)
        rot = random.uniform(0.0, 360.0)
        ent = RealObject(0, 0, rot)  
        self.world.addRealObject(ent)
        return ent
    
    def spawnRoundEntity(self,nothing):
        
        #x = random.uniform(-100.0, 100.0)
        x = random.uniform(-500.0, 500.0)
        y = random.uniform(-500.0, 500.0)
        rot = random.uniform(0.0, 360.0)
        ent = RealRoundObject(0, 0, "crosshair2.png", 50)  
        self.world.addRealObject(ent)
        return ent
    
    def spawnCar(self):
        
        #x = random.uniform(-100.0, 100.0)
        x = random.uniform(-100.0, 100.0)
        y = random.uniform(-100.0, 100.0)
        rot = random.uniform(0.0, 360.0)
        ent = Car(x, y, rot,self.world)
        
        self.world.addRealObject(ent)
        return ent
    
    def spawnDecal(self,x,y,rot):
        rot = math.degrees(-rot)
        ent = DecalObject(x, y, rot, 100)
        self.world.addDecalObject(ent)
        ent._set_rotation(rot)
        ent.rotation = rot
        
    def spawnBackgroundObject(self):
        
        #x = random.uniform(-100.0, 100.0)
        x = 0
        y = random.uniform(-100.0, 100.0)
        
        ent = RealObject(x, y, 0,"map2.png")
        ent.scale = 5  
        self.world.addBackgroundObject(ent)
        return ent
    
    def spawnPlayer(self):
        
        #x = random.uniform(-100.0, 100.0)
        x = 0
        y = random.uniform(-100.0, 100.0)
        rot = random.uniform(0.0, 360.0)
        ent = Pc(x, y, rot)  
        self.world.addPlayer(ent)
        globals.player = ent
        return ent
       
    def createCrosshair(self,win,cam):
    
        ent = CrossHair(self.world.flyingLayer)
        ent.setCamera(cam)
        ent.setWindow(win)
        win.notifyMouseEventsTo(ent)  
        self.world.addFlyingObject(ent)
        self.world.crosshair = ent
    

